package com.itany.corejava.day13;

import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public class TestRobot {


    private JFrame jf;

    private JTextArea jta;

    public TestRobot() {
        jf=new JFrame();
        jta=new JTextArea(20,40);
    }

    private void init(){
        jf.add(jta);
    }

    private void addEventHandler(){
        jta.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                if(KeyEvent.VK_A==e.getKeyCode()) {
                    try {
                        Robot robot = new Robot();

                        // robot.mouseMove(0,0);

                        robot.keyPress(KeyEvent.VK_B);

                    } catch (AWTException e1) {
                        e1.printStackTrace();
                    }
                }
            }
        });
    }

    public void show(){
        init();
        addEventHandler();
        jf.pack();
        jf.setVisible(true);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
        new TestRobot().show();
    }


}
